

(function( $ ){
    $(function() {
        var locat = (window.location+'').split('/'); 
    	if('pictures'== locat[3]){locat =  locat[0]+'//'+locat[2];}else{locat =  locat[0]+'//'+locat[2]+'/'+locat[3];};
    	$(".filePicker").each(function(i){
    		var target = $(this).attr("id");
	        uploader = WebUploader.create({
	            pick: {
	                id: '#'+target,
	                label: '选择文件'
	            },
	            formData: {uid: 123},
	            auto: true,
	            swf: './Uploader.swf',
	            chunked: false,
	            chunkSize: 512 * 1024,
	            server: locat+'/pictures/save.do',
	            accept: {
	                 title: '选择文件',
	                 extensions: 'gif,jpg,jpeg,bmp,png',
	                 mimeTypes: 'image/*'
	             },
	            disableGlobalDnd: true,
	            fileNumLimit: 100,
	            fileSizeLimit: 200 * 1024 * 1024,    // 20 M
	            fileSingleSizeLimit: 50 * 1024 * 1024    // 5 M
	        });
	        uploader.on( 'uploadSuccess', function( file,ret) {
	        	if(file){
	        		 uploader.makeThumb( file, function( error, src ) {
	        			 var $li = $( '<li class=\"brick\">' +
	     	                    '<div class="file-panel" style="height: 30px;"><span class="cancel" onclick="$(this).parent().parent().remove();">删除</span></div>'+
	     	                    '<p class="imgWrap"><img src="'+src+'"></p>'+
	        			 		'<input name="'+target+'" type="hidden" value="'+ret.name+'"</li>' );
	     	        	$("#"+target+"_list").append($li);
	     	        	$("#"+target+"_list").gridly();
	                 });
	        	}
	        });
	        
    	});
    });
})( jQuery );